#include "Poco/Task.h"
#include "Poco/ThreadPool.h"
#include "Poco/Mutex.h"
#include "Poco/Thread.h"

#include <iostream>

using namespace std;
using namespace Poco;
Mutex		mutex;
int test = 0;
class MyTask : public Runnable
{
public:
	MyTask():m_test(0)
	{
		m_thread.start(*this);
	}
	virtual void run();
    virtual ~MyTask()
	{
		m_thread.join();
	}
	int m_test;
	Thread		m_thread;
};

void MyTask::run()
{
	for(int i = 0; i < 30;i++)
	{
		{
			cout<<m_test<<endl;
			ScopedLock<Mutex> lock(mutex);
			m_test++;
		}
		Thread::sleep(1000);
	}
}

class MyTask2 : public Runnable
{
public:
	virtual void run();
};

void MyTask2::run()
{
	for(int i = 0; i < 30;i++)
	{
		{
			cout<<test<<endl;
			ScopedLock<Mutex> lock(mutex);
			test--;
		}
		Thread::sleep(1000);
	}
}

class MyTest
{
public:
	MyTest():m_test(0)
	{
		
	}
	virtual void add(){m_test++;}
    virtual ~MyTest()
	{
		cout<<m_test<<endl;
	}
	int m_test;
};
#include <vector>

int main(int argc, char *argv[])
{
// 	ThreadPool& defaultPool = ThreadPool::defaultPool();
// 	MyTask* task1 = new MyTask();
// 	//MyTask2* task2 = new MyTask2();
// 	defaultPool.start(*task1);
// 	//defaultPool.start(*task2);
// 	defaultPool.joinAll();
// 	
// 	delete task1;
// 	//delete task2;
	//MyTask task1;
	vector<MyTest>		vTest;
	for (int i = 0; i < 10; i++)
	{
		vTest.push_back(MyTest());
		vTest[i].add();
		cout << vTest[i].m_test<<endl;
	}

	return 0;
}
